package LABS.lab3;

/**************************************************************
* Class lab3
* @author Jeff Thomas - Thomas007
* @vesion 1.0.0
* Date: 02.19.2008
* Copyright 2008, Jeff Thomas
***************************************************************/
import javax.swing.JOptionPane;
import java.util.LinkedList;
import java.util.Iterator;

public class lab3
{
	public static void main(String[] args)
	{
	//create our list
	LinkedList<String> list = new LinkedList<String>();
	//populate the list of students
	populateList(list);
	//add student at the beginning and end
	addStudentFirst(list);
	addStudentLast(list);
	//display our new list
	displayList(list);
	System.out.println();
	//remove first student and Skyler from list
	removeStudentFirst(list);
	removeStudent(list);
	//display the list
	displayList(list);	
	}
/**************************************************************
* Populate List
* @param list - LinkedList of type String containing students
* Task:	1. Populate the list with students names
* Side Effects: None
***************************************************************/	
	public static void populateList(LinkedList<String> list)
	{
		list.add("Jeff");
		list.add("Joe");
		list.add("Taylor");
		list.add("Hannah");
		list.add("Skyler");
	}
/**************************************************************
* Display List
* @param list - LinkedList of type String containing students  
* Task:	1. Create iterator for the list
*			2. While loop through the list and print students names
* Side Effects: None
***************************************************************/	
	public static void displayList(LinkedList<String> list)
	{
		Iterator<String> iter = list.iterator();
		while (iter.hasNext())
			System.out.println(iter.next());
	}
/**************************************************************
* Add Student First
* @param list - LinkedList of type String containing students
* @param student - String containing new students name
* Task:	1. Add student to beginning of list
* Side Effects: None
***************************************************************/	
	public static void addStudentFirst(LinkedList<String> list)
	{
		String student = JOptionPane.showInputDialog(null, "Please input a name", "Input Student First", JOptionPane.PLAIN_MESSAGE);
		list.addFirst(student);
	}
/**************************************************************
* Add Student Last
* @param list - LinkedList of type String containing students
* @param student - String containing new students name
* Task:	1. Add student to end of list
* Side Effects: None
***************************************************************/	
	public static void addStudentLast(LinkedList<String> list)
	{
		String student = JOptionPane.showInputDialog(null, "Please input a name", "Input Student Last", JOptionPane.PLAIN_MESSAGE);
		list.addLast(student);
	}
/**************************************************************
* Remove Student First
* @param list - LinkedList of type String containing students
* @return - name of student removed
* Task:	1. Remove the first student from list
* Side Effects: None
***************************************************************/	
	public static String removeStudentFirst(LinkedList<String> list)
	{
		return list.removeFirst();
	}
/**************************************************************
* Add Student First
* @param list - LinkedList of type String containing students
* @param student - String containing new students name
* @return - Boolean of whether or not student was removed
* Task:	1. Add student to beginning of list
* Side Effects: None
***************************************************************/	
	public static boolean removeStudent(LinkedList<String> list)
	{
		String student = JOptionPane.showInputDialog(null, "Please input a name", "Remove Student", JOptionPane.PLAIN_MESSAGE);
		return list.remove(student);
	}
}

/**************************************************************
* I, Jeff Thomas, certify that each part of this program was
* written by me, except as noted within the code.
*
*						_________________________
***************************************************************/